<?php
/* @var $this ArticlesController */
/* @var $model Articles */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'articles-form',
	'htmlOptions'=>array(
		'class'=>'form-horizontal'
	),
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="form-group">

		<div class="col-sm-9">
			<?php echo $form->textFieldRow($model,'name',array('class'=>'span5','maxlength'=>200)); ?>
		</div>
	</div>
	<div class="space-4"></div>

	<div class="form-group">

		<div class="col-sm-9">
			<?php echo $form->textFieldRow($model,'alias',array('class'=>'span5','maxlength'=>200)); ?>
		</div>
	</div>
	<div class="space-4"></div>

	<div class="form-group">

		<div class="col-sm-9">
			<?php //echo $form->textAreaRow($model,'des',array('class'=>'span5','maxlength'=>200)); ?>
			<div class="wysiwyg-editor" id="editor1"></div>

		</div>
	</div>
	<div class="space-4"></div>

	
	
	<div class="form-group">

		<div class="col-sm-9">
			<?php echo $form->textFieldRow($model,'created',array('class'=>'span5','maxlength'=>200)); ?>
		</div>
	</div>
	<div class="space-4"></div>
	
	<div class="form-group">

		<div class="col-sm-9">
			<label for="Articles_created">Category</label>
			<select id="selectCat">
				<?php
				if(!empty($categories)){
					foreach($categories as $key=>$category){
						echo '<option value="'.outStr($category->id).'">'.$category->name.'</option>';
					}
				}
				?>
			</select>
		</div>
	</div>
	<script>
	var categories = [];
	
	$().ready(function(e){
		
		$("#selectCat").on("change",function(e){
			
			categories.push($(this).val());
			$("#categories").val(JSON.stringify(categories));
		});
		
		$('#editor1').css({'height':'200px'}).ace_wysiwyg({
			toolbar_place: function(toolbar) {
				return $(this).closest('.widget-box').find('.widget-header').prepend(toolbar).children(0).addClass('inline');
			},
			toolbar:
			[
				'font',
				null,
				'fontSize',
				null,
				{name:'bold', className:'btn-info'},
				{name:'italic', className:'btn-info'},
				{name:'strikethrough', className:'btn-info'},
				{name:'underline', className:'btn-info'},
				null,
				{name:'insertunorderedlist', className:'btn-success'},
				{name:'insertorderedlist', className:'btn-success'},
				{name:'outdent', className:'btn-purple'},
				{name:'indent', className:'btn-purple'},
				null,
				{name:'justifyleft', className:'btn-primary'},
				{name:'justifycenter', className:'btn-primary'},
				{name:'justifyright', className:'btn-primary'},
				{name:'justifyfull', className:'btn-inverse'},
				null,
				{name:'createLink', className:'btn-pink'},
				{name:'unlink', className:'btn-pink'},
				null,
				{name:'insertImage', className:'btn-success'},
				null,
				'foreColor',
				null,
				{name:'undo', className:'btn-grey'},
				{name:'redo', className:'btn-grey'}
			],
			speech_button:false
		});
	});
	function showErrorAlert (reason, detail) {
		console.log(reason);
		var msg='';
		if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
		else {
			console.log("error uploading file", reason, detail);
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	}
	</script>
	
	<div class="col-sm-9" style="display:none">
			<label for="Articles_des">Category list</label>
			<textarea class="span5" maxlength="200" name="Articles[categories]" id="categories"></textarea>		</div>
	<div class="space-4"></div>
		<div class="col-sm-9" style="display:">
			<label for="Articles_des">Images list</label>
			<textarea class="span5" maxlength="200" name="Articles[images]" id="Categories_image_id"></textarea>		</div>
	<div class="space-4"></div>
	<div class="form-group">

		<div class="col-sm-9">
			<?php echo $form->textFieldRow($model,'user_id',array('class'=>'span5','maxlength'=>200)); ?>
		</div>
	</div>
	<div class="space-4"></div>


	
	<div class="clearfix form-actions">
		<div class="col-md-offset-3 col-md-9">
			<?php $this->widget('bootstrap.widgets.TbButton', array(
				'buttonType'=>'submit',
				'type'=>'primary',
				'label'=>$model->isNewRecord ? 'Create' : 'Save',
				'htmlOptions'=>array('class'=>'button')
			)); ?>
		</div>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->